<?php

namespace App\Http\Requests;


class AuthorizationsRequest extends FormRequest
{

    public function rules(): array
    {
        return [
            'phone' => 'required|regex:/^1[3456789]\d{9}$/',
            'type' => ['required', 'string', 'in:password,sms', function ($attribute, $value, $fail) {
                if ($value == 'password' && !$this->has('password')) {
                    return $fail('请输入密码');
                }
                if ($value == 'sms' && !$this->has('code')) {
                    return $fail('请输入验证码');
                }
            }],

        ];
    }


    public function attributes(): array
    {
        return [
            'phone' => '手机号'
        ];
    }
}
